<!DOCTYPE hrml>
<html>
<head>
    <title>运费</title>
    <include file='public/head'>
    <style>
        .layui-legend-size{font-size:14px !important;}
        .layui-nopadding{padding:0 !important;}
        .layui-overflow{overflow:auto;}
        .layui-nomargin{margin: 0 !important;}
        .layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}
        .layui-input{height:30px !important; }
        .layui-form-search-item .layui-inline{margin-bottom: 5px;}
        .layui-form-search-item label{margin-left: 15px;}
        .layui-table-page {padding: 7px 0px 0px;}
        .layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}
    </style>
</head>
<body>
    <!-- layui-tab开始 -->
    <div class="layui-tab" lay-fliter="demo-tab">
        <!-- 顶部导航菜单开始 -->
        <div class="layui-tab-nav">
            <ul class="layui-tab-title">
                {:getNav('goods','freight_plugin/index')};
            </ul>
        </div>
        <!-- 内容开始 -->
        <div class="layui-card">
            <eq name="allow" value="true">
                <!-- 搜索栏开始 -->
                <fieldset class="layui-elem-field layui-field-title layui-field-padding">
                    <legend class="layui-legend-size">搜索</legend>
                    <form class="layui-form table-bar" action="{:cmf_plugin_url('Goods://freight_plugin/index')}" lay-filter="form-bar" method="post">
                        <div class="layui-form-search-item">
                            <div class="layui-inline" >
                                <div class="layui-input-inline" style="width: 100px;">
                                    <select name="search[store_type]" lay-verify="" class="layui-input">
                                        <option value="1" <eq name="search.store_type" value="1">selected</eq> >店铺ID</option>
                                    </select>
                                </div>
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="search[store_title]" autocomplete="off" placeholder="请输入内容" class="layui-input" value="{$search.store_title}" style="width: 100px;">
                                </div>
                            </div>
                            <div class="layui-inline" >
                                <div class="layui-input-inline" style="width: 100px;">
                                    <select name="search[freight_type]" lay-verify="" class="layui-input">
                                        <option value="1" <eq name="search.freight_type" value="1">selected</eq> >模板名称</option>
                                        <option value="2" <eq name="search.freight_type" value="2">selected</eq> >模板ID</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline" >
                                <div class="layui-input-inline" style="width: 100px;">
                                    <input type="text" name="search[freight_title]" autocomplete="off" placeholder="请输入内容" class="layui-input" value="{$search.freight_title}" style="width: 100px;">
                                </div>
                            </div>

                            <div class="layui-inline">
                                <button type="submit" class="layui-btn layui-btn-sm layui-btn-primary " style="font-weight:800;" lay-submit="" lay-filter="demo2"><i class="layui-icon ">&#xe615;</i>搜索</button>
                            </div>

                        </div>
                    </form>
                </fieldset>
                <!-- 搜索栏结束 -->
            </eq>
            <!-- 表头按钮开始 -->
            <div class="layui-card-header layui-bg-gray layui-bottom">
                <a href="javascript:;" class="layui-btn layui-btn-xs add-config-btn">
                    <i class="fa fa-plus-circle normal"></i> 添加运费模板
                </a>
                <a href="javascript:;" class="layui-btn layui-btn-xs layui-btn-danger delete-btn" >批量删除</a>

            </div>
            <!-- 表头按钮结束 -->

            <!-- 数据表格开始 -->
            <form method="post" id="f">
            <table class="layui-table layui-nomargin">
                <thead>
                    <tr>
                        <th rowspan="2" style="text-align:center; width: 20px;">
                            <input type="checkbox"  id="check-box-all" >
                        </th>
                        <eq name="allow" value="true">
                        <th style="width:45px;">店铺ID</th></eq>
                        <th style="width:60px;">ID</th>
                        <th>模板名称</th>
                        <th>计费规则</th>
                        <th>首件</th>
                        <th>首费</th>
                        <th>续件</th>
                        <th>续费</th>
                        <th>操作</th>
                    </tr>

                </thead>
                <tbody>
                    <volist  name="data" id="vo">
                        <tr lay-fliter="test3">
                            <th style="text-align:center;">
                                <input type="checkbox" class="check-box " name="id[]" value="{$vo['id']}">
                            </th>
                            <eq name="allow" value="true">
                            <td>{$vo.store_id}</td></eq>
                            <td>{$vo.id}</td>
                            <td>{$vo.title}</td>
                            <td>
                                <if condition="$vo.type eq 1">
                                包邮
                                <else>
                                按件数
                               </if>
                            </td>
                            <td>{$vo.default_num}</td>
                            <td >{$vo.default_price}</td>
                            <td >{$vo.continue_num}</td>
                            <td >{$vo.continue_price}</td>
                            <td >
                                <button type="button" data-id="{$vo.id}" class="layui-btn layui-btn-primary layui-btn-xs view-btn" title="查看"><i class="layui-icon">&#xe602;</i></button>
                                <neq name="vo.id" value="1">
                                <button type="button" data-id="{$vo.id}" class="layui-btn layui-btn-primary layui-btn-xs delete-btn" title="删除"><i class="layui-icon">&#xe640;</i></button>
                                </neq>
                            </td>
                        </tr>
                    </volist>
                </tbody>
            </table>
            <!--分页开始-->
            <div class="layui-table-page">
                <div id="layui-table-page1">
                    <div class="layui-box layui-laypage layui-laypage-default" id="layui-laypage-1">
                        {$page|default=''}
                    </div>
                </div>
            </div>
            <!-- 分页结束 -->
            </form>
            <!-- 数据表格结束 -->
        </div>
        <!-- 内容结束 -->
    </div>
    <!-- layui-tab结束 -->
    <include file='public/scripts'>

    <script>
    //全选/取消
    $('#check-box-all').on('click',function(){
        console.log(1111);
        $('.check-box').prop('checked',$('#check-box-all').prop('checked'));
        console.log($('#check-box-all').prop('checked'));
    });
    layui.use('laydate', function(){
          var laydate = layui.laydate;

          //执行一个laydate实例

          laydate.render({
            elem: '#test2' //指定元素
          });
            //年月选择器
          laydate.render({
            elem: '#test3'
          });
        });
    function sort(){
        $("#f").submit();
    }


    //添加运费模板
    $('.add-config-btn').on('click',function(){
        let url = "{:cmf_plugin_url('Goods://freight_plugin/addFreightPage')}";
        layer.open({
            type: 2//基本层类型  0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
            ,title: '添加'//层的标题
            ,shadeClose: true//是否点击遮罩关闭
            ,shade: 0.8//遮罩
            ,area: ['1000px', '800px']//宽高
            ,btn:['提交','关闭']//弹框按钮
            ,fixed:false//固定
            ,content: url //iframe的url
            ,yes:function(index, layero){
            //子页面的请求操作都放子页面
                var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：
                iframeWin.addFreightConfig();
            }
            ,btn2:function(index, layero){
            }
        });
    })

    //查看运费
    $('.view-btn').on('click',function(){
        let id = $(this).data('id');
        let url = "{:cmf_plugin_url('Goods://freight_plugin/detailFreightPage')}?id="+id;
        layer.open({
            type: 2//基本层类型  0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
            ,title: '查看'//层的标题
            ,shadeClose: true//是否点击遮罩关闭
            ,shade: 0.8//遮罩
            ,area: ['1000px', '800px']//宽高
            ,btn:[]//弹框按钮
            ,fixed:false//固定
            ,content: url //iframe的url
            ,btn1:function(index, layero){
            }
        });
    })
    //删除
    $('.delete-btn').on('click',function(){
        var id_str = $('input[type=checkbox]:checked').map(function(){return this.value}).get().join(',');
        let id = $(this).data('id');
        if(id == undefined) id = id_str;
        //询问
        layer.confirm('确定要删除吗？',{icon:3,title:'提示',btn:['删除','取消']}
        ,function(index,layero){
            $.ajax({
                url:"{:cmf_plugin_url('Goods://freight_plugin/delete')}",
                type:'post',
                data:{id:id},
                success:function(data){
                    let icon = ( data.code == 200 ) ? 1 : 5 ;
                    layer.msg( data.message , { time:1200 , icon:icon },function(){
                        window.location.reload();
                    });
                },
                error:function(data){
                    console.log(data);
                    layer.msg('系统错误',{time:1200,icon:5});
                }
            })
        },function(index){});

    })


    </script>
</body>
</html>